package com.taotao.portal.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.taotao.po.TbContent;
import com.taotao.portal.service.PortalContentService;
import com.taotao.util.JsonUtils;

/**
 * 首页访问Controller
 * 
 * @author DaiRui
 * @ClassName : IndexController
 * @Description:
 * @date 2017年4月5日 下午8:29:24
 * @Version 1.0
 */

@Controller
public class IndexController {

	@Autowired
	private PortalContentService contentService;

	@RequestMapping(value="/index")
	public String showIndex(Model model) {
		// 首页大广告为categoryId固定为89。
		List<TbContent> list = contentService.getContentList(89l);
		List<Map> resultList = new ArrayList<>();
		for (TbContent tbContent : list) {
			Map<String, Object> item = new HashMap<>();
			item.put("src", tbContent.getPic());
			item.put("width", 670);
			item.put("height", 240);
			item.put("srcB", tbContent.getPic2());
			item.put("widthB", 550);
			item.put("heightB", 240);
			item.put("href", tbContent.getUrl());
			item.put("alt", tbContent.getTitle());
			resultList.add(item);
		}
		String json = JsonUtils.objectToJson(resultList);
		model.addAttribute("ad1", json);
		return "index";
	}
}
